/*
 * @Description: 
 * @Author: iamsmiling
 * @Date: 2021-05-22 17:28:48
 * @LastEditTime: 2021-06-15 14:51:29
 */
import 'package:credit_business_circle/R/R.dart';
import 'package:credit_business_circle/components/convex_bottom_bar/convex_bottom_bar.dart';
import 'package:credit_business_circle/domain/local/bottom_navigation_bar_item_entity.dart';

import 'package:credit_business_circle/pages/main_controller.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

class MainPage extends StatelessWidget {
  const MainPage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return GetBuilder<MainController>(builder: (_) {
      return Scaffold(
        floatingActionButton: GetBuilder<MainController>(builder: (_) {
          return Visibility(
            visible: _.currentIndex == 0,
            child: FloatingActionButton(
              onPressed: () {},
              child: Image.asset(R.image.scrollToTop),
            ),
          );
        }),
        body: IndexedStack(
          index: _.currentIndex,
          children: [
            for (Widget w in _.pages)
              Visibility(visible: w == _.pages[_.currentIndex], child: w)
          ],
        ),
        bottomNavigationBar: ConvexAppBar(
            backgroundColor: R.color.ffffffff,
            height: R.dimen.dp48,
            elevation: 0,
            style: TabStyle.fixed,
            onTap: _.switchTo,
            activeColor: R.color.ff2eab86,
            color: R.color.ff888888,
            items: [
              for (BottomNavigationBarItemEntity item in _.items)
                TabItem(
                    activeIcon: Image.asset(
                      item.icon,
                      color: item.label.isNotEmpty ? R.color.ff2eab86 : null,
                    ),
                    icon: Image.asset(
                      item.icon,
                      color: item.label.isNotEmpty ? R.color.ff888888 : null,
                    ),
                    title: item.label)
            ]),
      );
    });
  }
}
